package com.movie.repository;

import com.movie.entity.VipLevel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface VipLevelRepository extends JpaRepository<VipLevel, Long> {
    
    Optional<VipLevel> findByName(String name);
    
    Optional<VipLevel> findByLevel(Integer level);
    
    List<VipLevel> findByStatusOrderBySortOrderAsc(Boolean status);
    
    @Query("SELECT v FROM VipLevel v WHERE v.status = true ORDER BY v.sortOrder ASC")
    List<VipLevel> findActiveLevels();
    
    @Query("SELECT v FROM VipLevel v WHERE v.level <= :maxLevel AND v.status = true ORDER BY v.level ASC")
    List<VipLevel> findLevelsUpTo(@Param("maxLevel") Integer maxLevel);
}